self.arg_dict = {}
self.key_ord = []
self.key_dict = {}
- for (name, type) in paramspec:
+ for (name, typ) in paramspec:
self.arg_ord.append(name)
- self.arg_dict[name] = type
- for (name, type) in keyspec:
+ self.arg_dict[name] = typ
+ for (name, typ) in keyspec:
self.key_ord.append(name)
- self.key_dict[name] = type
+ self.key_dict[name] = typ
def get_args(self, d, xargs=None):
args = {}
def split_args(self, d, args, keys):
for (k, v) in d.items():
if k in self.arg_dict:
- type = self.arg_dict[k]
- val = self.coerce(type, v)
+ typ = self.arg_dict[k]
+ val = self.coerce(typ, v)
args[k] = val
elif k in self.key_dict:
- type = self.key_dict[k]
- val = self.coerce(type, v)
+ typ = self.key_dict[k]
+ val = self.coerce(typ, v)
keys[k] = val
else:
raise ArgError('Invalid parameter: %s' % k)
d[k] = val
return self.get_args(d, xargs=xargs)
- def coerce(self, type, v):
+ def coerce(self, typ, v):
try:
- if type == 'int':
+ if typ == 'int':
val = int(v)
- elif type == 'long':
+ elif typ == 'long':
val = long(v)
- elif type == 'str':
+ elif typ == 'str':
val = str(v)
- elif type == 'sxpr':
+ elif typ == 'sxpr':
val = self.sxpr(v)
- elif type == 'bool':
+ elif typ == 'bool':
val = self.bool(v)
else:
- raise ArgError('invalid type:' + str(type))
+ raise ArgError('invalid type:' + str(typ))
return val
except ArgError:
raise
Used on the client.
"""
- def __init__(self, fn, paramspec, keyspec={}):
+ def __init__(self, fn, paramspec, keyspec = None):
+ if keyspec == None:
+ keyspec = {}
Args.__init__(self, paramspec, keyspec)
self.fn = fn
Used in the HTTP server.
"""
- def __init__(self, fn, paramspec, keyspec={}):
+ def __init__(self, fn, paramspec, keyspec = None):
+ if keyspec == None:
+ keyspec = {}
Args.__init__(self, paramspec, keyspec)
self.fn = fn
self.lock.release()
if async:
- scheduler.now(self.call_handlers, [event, val])
+ scheduler.now(self.call_handlers, event, val)
else:
self.call_handlers(event, val)
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#============================================================================
# Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
+# Copyright (C) 2005 XenSource Ltd
#============================================================================
"""Xend interface to networking control scripts.
"""
import os
import os.path
-import sys
import xen.util.process
from xen.xend import XendRoot
vif = vif_old
return vif
-def vifctl(op, vif=None, script=None, domain=None, mac=None, bridge=None, ipaddr=[]):
+def vifctl(op, vif=None, script=None, domain=None, mac=None, bridge=None, ipaddr=None):
"""Call a vif control script.
Xend calls this when bringing vifs up or down.
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#============================================================================
# Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
+# Copyright (C) 2005 XenSource Ltd
#============================================================================
import threading
-def later(delay, fn, args=(), kwargs={}):
+def later(delay, fn, *args, **kwargs):
"""Schedule a function to be called later.
@param delay: delay in seconds
timer.start()
return timer
-def now(fn, args=(), kwargs={}):
+def now(fn, *args, **kwargs):
"""Schedule a function to be called now.
@param fn: function
# Copyright (C) 2005 Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
+# Copyright (C) 2005 XenSource Ltd
# This file is subject to the terms and conditions of the GNU General
# Public License. See the file "COPYING" in the main directory of
xs = None
xslock = threading.Lock()
- def __init__(self, path, fn, args=(), kwargs={}):
+ def __init__(self, path, fn, *args, **kwargs):
self.fn = fn
self.args = args
self.kwargs = kwargs
cls.threadcond.release()
while True:
try:
- (ord, owr, oer) = select.select([ cls.xs ], [], [])
+ (fd, _1, _2) = select.select([ cls.xs ], [], [])
cls.xslock.acquire()
# reconfirm ready to read with lock
- (ord, owr, oer) = select.select([ cls.xs ], [], [], 0.001)
- if not cls.xs in ord:
+ (fd, _1, _2) = select.select([ cls.xs ], [], [], 0.001)
+ if not cls.xs in fd:
cls.xslock.release()
continue
we = cls.xs.read_watch()